import axios from 'axios'

axios.defaults.baseURL = process.env.NODE_ENV === 'development' ? '/conner' : '生产环境源'
axios.defaults.timeout = 6000
// 类似于 qs 依赖 使json 数据转换为 字符串：商品列表v2数据一直无限刷新无底线的原因
// 也适用于 小程序
axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded';


// Add a request interceptor 添加拦截器
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
}, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
});

export default axios